#include <iostream>

using namespace std;

const int N = 1e5 + 10;
int a[N] , dp[N];
int n , len;


int main()
{
    cin >> n;
    for(int i = 1;i <= n;i ++) cin >> a[i];
    for(int i = 1;i <= n;i ++)
    {
        if(len == 0 || a[i] > dp[len]) dp[++len] = a[i];
        else
        {
            int l = 1 , r = len;
            while(l < r)
            {
                int mid = (l + r) / 2;
                if(a[i] <= dp[mid]) r = mid;
                else l = mid + 1;
            }
            dp[l] = a[i];
        }
    }
    cout << len << endl;
    return 0;
}